import { Tag, Space } from 'antd';
import styles from './index.less';

interface columnsProps {
  handleDetails: (value: any) => void;
  handlePost: (value: any) => void;
}

const columns = ({ handleDetails, handlePost }: columnsProps) => [
  {
    title: '单号',
    dataIndex: 'order_no',
  },
  {
    title: '用户',
    dataIndex: 'user',
    render: (_text: any, record: any) => {
      return <span>{record.user.name}</span>;
    },
  },
  {
    title: '金额',
    dataIndex: 'amount',
  },
  {
    title: '状态',
    dataIndex: 'status',
    render: (_text: any, record: any) => {
      switch (record.status) {
        case 1:
          return <Tag color="lime">下单</Tag>;
        case 2:
          return <Tag color="cyan">支付</Tag>;
        case 3:
          return <Tag color="green">发货</Tag>;
        case 4:
          return <Tag color="purple">收货</Tag>;
        case 5:
          return <Tag color="default">过期</Tag>;
        default:
          return record.status;
      }
    },
  },
  {
    title: '支付时间',
    dataIndex: 'pay_time',
  },
  {
    title: '支付类型',
    dataIndex: 'pay_type',
  },
  {
    title: '支付单号',
    dataIndex: 'trade_no',
  },
  {
    title: '操作',
    key: 'action',
    render: (text: any, record: any) => (
      <Space size="middle">
        <span className={styles.editBtn} onClick={() => handleDetails(record)}>
          详情
        </span>
        {record.status >= 3 ? (
          ''
        ) : (
          <span className={styles.editBtn} onClick={() => handlePost(record)}>
            发货
          </span>
        )}
      </Space>
    ),
  },
];

export default columns;
